<?php
include '../../../common.inc.php';
include 'fun.php';
$mysqli = new mysqli('localhost', 'root', '', 'test_data');
# select py, id, dianming from koubei_myisam2 where LENGTH(py) =2 and length(dianming)=12
# select py, id, dianming, chengshi from koubei_myisam2 where LENGTH(py) =3
# --尚未检测__,
# 重复的加上地区后缀
# 更新服务商类型
# 小于四个字符的
# 空字符的
# 转换为小写
$start = isset($start) ? (int) $start : 0;
$sql = "select py, id, dianming from koubei_myisam2 where id>{$start} order by id ASC limit 100";

$result = $mysqli->query($sql);
$res = $result->fetch_all(MYSQLI_ASSOC);
if (!$res) exit('No More Results');

foreach ($res as $r) {
	$dianming = str_replace(
		array(' ', '&amp;'  , '·', '&middot;', '&', '。'   , '、' , '【' , '】', '（', '）', '！', 'Ⅱ','Ｓ', '―', '，', '：', '★', '《','》', '◥','◣', '◢','◤'),
		array('_', '_'      , '_', '_'       , '_', ''     , ''   , ''  , ''  , '_' ,'_'  , '_', '2','s', '_', '_' , '_' , ''  , ''  , '', '', '', ''  , ''),
		$r['dianming']
	);

	if (iconv_strlen($r['py']) !=  iconv_strlen($dianming, DT_CHARSET)) {

		$strArray = str2array($dianming);
		$py = '';

		foreach($strArray as $char) {
			$pyi = gb2py2($char);

			if ($pyi === '') {
				$pinyin = substr(stranger2py('pinyin.txt', $char), 0, 1);
				if ($pinyin !== false) {
					$pyi = substr($pinyin, 0, 1);
				} else {
					exit($char);
				}
			}
			$py .= $pyi;
		}
		$sql = "update koubei_myisam2 set py ='{$py}', dianming='{$dianming}' WHERE ID = {$r['id']}";
		$mysqli->query($sql);
	} else {
		continue;
	}

}
$start = (int) ($r['id']-1);
echo '<meta http-equiv="refresh" content="0; url='.$_SERVER['PHP_SELF'].'?start='.$start.'" />';
echo '<pre style="font-size:100px;">';
echo $r['id'] .'-'. $r['dianming'];

?>